package com.mairuide.agency.controller;

import com.mairuide._frame.base.BaseController;
import com.mairuide.agency.pojo.Agency;
import com.mairuide.agency.service.AgencyService;
import com.mairuide.entity.Result;
import com.mairuide.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Date;

/**
 * @Description
 * @auther 刘中华
 * @create 2019-01-15 11:33
 */
@Controller
@CrossOrigin
@RequestMapping("/agency")
public class AgencyController extends BaseController {
    @Autowired
    AgencyService agencyService;

    /**
     * 增加
     * @param case
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(method= RequestMethod.POST,value = "add")
    public Result add(@RequestBody Agency agency) throws Exception{
        String caseId = request.getSession().getAttribute("caseId") == null?"":request.getSession().getAttribute("caseId").toString();
        agency.setCreate_time(new Timestamp(new Date().getTime()));
        agency.setCreate_id(super.getLoginUser().getId());
        agency.setCasemanage_id(caseId);
        agency.setState(0);
        agencyService.save(agency);
        return new Result(true, StatusCode.OK,"增加成功");
    }
}
